package mt.demo.web.comm.VelocityResolverArg;

import jodd.datetime.JDateTime;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by mt on 2015-8-24.
 * 后台数据显示到前台解析器
 */
@Component
public class YomsVelocityTools {
    /**
     * 转换java时间为yyyy-MM-dd HH:mm:ss
     *
     * @param
     * @return
     */
    public String getDate(Date date) {
        JDateTime dateTime = new JDateTime(date);
        return dateTime.toString("YYYY-MM-DD");
    }

    /**
     * 转换java时间为yyyy-MM-dd HH:mm
     *
     * @param date
     * @return
     */
    public String getDateTime(Date date) {
        JDateTime dateTime = new JDateTime(date);
        return dateTime.toString("YYYY-MM-DD hh:mm");
    }

    /**
     * 转换java时间为hh:mm
     *
     * @param date
     * @return
     */
    public String getTime(Date date) {
        JDateTime dateTime = new JDateTime(date);
        return dateTime.toString("hh:mm");
    }

    /**
     * 把1、2转为否、是
     */
    public String getword(int IsPass) {
        if (IsPass == 1) {
            String pass=String.valueOf(IsPass);
            return pass.replace("1","否");
        } else if (IsPass == 2) {
            String pass=String.valueOf(IsPass);
            return pass.replace("2","是");
        }
        return "是";
    }

}
